﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Text;

namespace EmployeeCheckIn
{
    public partial class ShowDataEmp : System.Web.UI.Page
    {
        
        protected void Page_Load(object sender, EventArgs e)
        {
            
        

       
            if (Session["User"] != null && Session["Pass"] != null)
            {
                EmpEntity emp = new EmpEntity();
                DataTable dt = new DataTable();
                dt = (DataTable)Session["Showdata"];                
                if (dt != null && dt.Rows.Count > 0)
                {
                    hdf1.Value = dt.Rows[0]["EMP_ID"].ToString();
                    txtEMP_CODE.Text = dt.Rows[0]["emp_code"].ToString();
                    rbltitle.SelectedValue = dt.Rows[0]["emp_title"].ToString();
                    txtEMP_FIRSTNAME.Text = dt.Rows[0]["emp_firstname"].ToString();
                    txtEMP_LASTNAME.Text = dt.Rows[0]["emp_lastname"].ToString();
                    ddlposition2.SelectedValue = dt.Rows[0]["emp_position_id"].ToString();
                    txtEMP_START_DATE.Text = Convert.ToDateTime(dt.Rows[0]["emp_start_date"].ToString()).ToString("dd/MM/yyyy", new System.Globalization.CultureInfo("th-TH"));
                    txtEMP_BIRTH_DATE.Text = Convert.ToDateTime(dt.Rows[0]["emp_birth_date"].ToString()).ToString("dd/MM/yyyy", new System.Globalization.CultureInfo("th-TH"));
                    txtEMP_ID_CARD.Text = dt.Rows[0]["emp_id_card"].ToString();
                    txtEMP_ADDRESS.Text = dt.Rows[0]["emp_address"].ToString();
                    ddlProvince.SelectedValue = dt.Rows[0]["emp_province_id"].ToString();
                    txtEMP_POST_CODE.Text = dt.Rows[0]["emp_post_code"].ToString();
                    txtEMP_PHONE.Text = dt.Rows[0]["emp_phone"].ToString();
                    ddlStatus2.SelectedValue = dt.Rows[0]["emp_status_id"].ToString();
                    imEmp.ImageUrl = dt.Rows[0]["emp_pic"].ToString();
                    //lbNotFound.Visible = false;
                }
                else
                {
                    //lbNotFound.Visible = true;
                }
            }
            else
            {
                Response.Redirect("Default.aspx");
            }
            
        }
        public DateTime ConvestToDate(string s)
        {
            int day = 1;
            int mount = 1;
            int years = 1111;
            try
            {
                try
                {
                    string[] stemp = s.Split('-');
                    day = Convert.ToInt32(stemp[0]);
                    mount = Convert.ToInt32(stemp[1]);
                    years = Convert.ToInt32(stemp[2]);
                }
                catch (Exception)
                {

                    string[] stemp = s.Split('/');
                    day = Convert.ToInt32(stemp[0]);
                    mount = Convert.ToInt32(stemp[1]);
                    years = Convert.ToInt32(stemp[2]);
                }
               
               
                if (years > 2300)
                {
                    years = years - 543;
                }
                return new DateTime(years, mount, day);
            }
            catch (Exception)
            {

                txtEMP_START_DATE.Visible = true;
                txtEMP_START_DATE.Text = "*รูปแบบ วว/ดด/ปปปป";
                txtEMP_START_DATE.Visible = true;
                txtEMP_START_DATE.Text = "*รูปแบบ วว/ดด/ปปปป";
            }

            return new DateTime(years, mount, day);

        }
        public bool CheckConvestToDate(string s)
        {
            int day;
            int mount;
            int years;
            bool resault = false;
            try
            {
                try
                {
                    string[] stemp = s.Split('-');
                    day = Convert.ToInt32(stemp[0]);
                    mount = Convert.ToInt32(stemp[1]);
                    years = Convert.ToInt32(stemp[2]);
                }
                catch (Exception)
                {

                    string[] stemp = s.Split('/');
                    day = Convert.ToInt32(stemp[0]);
                    mount = Convert.ToInt32(stemp[1]);
                    years = Convert.ToInt32(stemp[2]);
                }
               
               
                if (years > 2300)
                {
                    years = years - 543;
                }
                return resault = true;
             } 
                catch (Exception)
                {

                resault = false;
                }
                return resault;
            
        }

            protected void btBack_Click(object sender, ImageClickEventArgs e)
        {
            if (Session["User"] != null && Session["Pass"] != null)
            {
                Server.Transfer("MenuAdmin.aspx");
            }
            else
            {
                Response.Redirect("ShowList_Empoyee.aspx");
            }
        }

            protected void btNext_Click1(object sender, ImageClickEventArgs e)
            {
                if (Session["User"] != null && Session["Pass"] != null)
                {
                    Server.Transfer("MenuAdmin.aspx");
                }
                else
                {
                    Response.Redirect("ShowTime_Empoyee.aspx");
                }
            }

            protected void Back_Click(object sender, EventArgs e)
            {
                if (Session["User"] != null && Session["Pass"] != null)
                {
                    Server.Transfer("ShowList_Empoyee.aspx");
                }
                else
                {
                    Response.Redirect("Default.aspx");
                }
            }
    }
}
        
    

